/*
 * Created by 2019年4月17日
 */
package top.v5it.japi.ddd.core.dao.impl.mybatis;

import org.apache.ibatis.cursor.Cursor;
import org.springframework.dao.DataAccessException;
import top.v5it.japi.ddd.core.dao.impl.Condition;

import java.util.List;
import java.util.Map;

/**
 * The generic dao which persist data with mybatis.
 *
 * @author fangang
 */
public interface GenericDao {
    /**
     * @param tableName
     * @param keys
     * @param values
     * @throws DataAccessException
     */
    void insert(String tableName, List<Object> keys, List<Object> values) throws DataAccessException;

    /**
     * @param tableName
     * @param keys
     * @param pks
     * @throws DataAccessException
     */
    void update(String tableName, List<Map<Object, Object>> keys, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * @param tableName
     * @param pks
     * @throws DataAccessException
     */
    void delete(String tableName, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * @param tableName
     * @param pks
     * @throws DataAccessException
     */
    void deleteForList(String tableName, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * @param tableName
     * @param pks
     * @return result set
     * @throws DataAccessException
     */
    List<Map<String, Object>> load(String tableName, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * @param tableName
     * @param pks
     * @return result set
     * @throws DataAccessException
     */
    List<Map<String, Object>> find(String tableName, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * @param tableName
     * @param pks
     * @return
     * @throws DataAccessException
     */
    Cursor<Map<String, Object>> cursor(String tableName, List<Map<Object, Object>> pks) throws DataAccessException;

    /**
     * 按条件查找
     *
     * @param tableName
     * @param params
     * @param segment
     * @return
     * @throws DataAccessException
     */
    List<Map<String, Object>> findByCondition(String tableName, List<Condition> params, Map<String, Object> segment) throws DataAccessException;

    /**
     * 按组合查找
     *
     * @param tableName
     * @param keys
     * @param params
     * @param segment
     * @return
     * @throws DataAccessException
     */
    List<Map<String, Object>> loadAllByCombination(List<String> keys, String tableName, List<Condition> params, Map<String, Object> segment) throws DataAccessException;

    /**
     * 执行传递的sql
     *
     * @param sql
     * @return
     */
    List<Map<String, Object>> execute(String sqlText, Map<String, Object> val);

    /**
     * @param sqlText
     * @param val
     * @return
     * @throws DataAccessException
     */
    Cursor<Map<String, Object>> executeCursor(String sqlText, Map<String, Object> val) throws DataAccessException;
}
